package com.example.mall.web.controller;

import com.example.mall.dto.SentMessagesDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.service.ISentMessagesService;
import com.example.mall.domain.SentMessages;
import com.example.mall.query.SentMessagesQuery;
import com.example.mall.result.JSONResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sentMessages")
public class SentMessagesController {

    @Autowired
    public ISentMessagesService sentMessagesService;

    /**
     * 分页查询发送消息表信息
     * @param sentMessagesQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询发送消息表信息",notes = "分页查询发送消息表信息",httpMethod = "GET")
    public JSONResult queryPage(SentMessagesQuery sentMessagesQuery){
        PageDTO<SentMessagesDto> sentMessagesDtoPageDTO = sentMessagesService.queryPage(sentMessagesQuery);
        return JSONResult.success("查询成功",sentMessagesDtoPageDTO);
    }

    /**
     * 根据id查询发送消息表信息
     * @param sentId
     * @return
     */
    @GetMapping("query/{sentId}")
    @ApiOperation(value = "根据id查询发送消息表信息",notes = "根据id查询发送消息表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("sentId")Long sentId){
        //1.根据id查询用户信息
        if (sentId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SENTID_NOT_ID);
        }
        SentMessages sentMessages = sentMessagesService.getById(sentId);
        return JSONResult.success("查询成功",sentMessages);
    }

    /**
     * 根据id查询发送消息表信息
     * @param sentId
     * @return
     */
    @GetMapping("querySentMessagesById/{sentId}")
    @ApiOperation(value = "根据id查询发送消息表信息",notes = "根据id查询发送消息表信息",httpMethod = "GET")
    public JSONResult querySentMessagesById(@PathVariable("sentId")Long sentId){
        //1.根据id查询用户信息
        if (sentId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SENTID_NOT_ID);
        }
        SentMessages sentMessages = sentMessagesService.querySentMessagesById(sentId);
        return JSONResult.success("查询成功",sentMessages);
    }

    /**
     * 查询全部发送消息表信息
     * @param
     * @return
     */
    @GetMapping("querySentMessagesList")
    @ApiOperation(value = "查询全部发送消息表信息",notes = "查询全部发送消息表信息",httpMethod = "GET")
    public JSONResult querySentMessagesList(){
        List<SentMessages> sentMessages = sentMessagesService.querySentMessagesList();
        return JSONResult.success("查询成功",sentMessages);
    }

    /**
     * 新增发送消息表
     * @param sentMessagesDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增发送消息表",notes = "新增发送消息表",httpMethod = "POST")
    public JSONResult insert(@RequestBody SentMessagesDto sentMessagesDto){
        sentMessagesService.insert(sentMessagesDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改发送消息表信息
     * @param sentMessagesDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改发送消息表信息",notes = "修改发送消息表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody SentMessagesDto sentMessagesDto){
        sentMessagesService.update(sentMessagesDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除发送消息表信息
     * @param sentId
     * @return
     */
    @PostMapping("delete/{sentId}")
    @ApiOperation(value = "删除发送消息表信息",notes = "删除发送消息表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("sentId") Long sentId) {
        sentMessagesService.delete(sentId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除发送消息表信息
     * @param sentIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除发送消息表信息",notes = "批量删除发送消息表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> sentIds) {
        sentMessagesService.deleteBatch(sentIds);
        return JSONResult.success("批量删除成功");
    }
}
